//
//  HotSiteDetailViewController.m
//  旅游咨询
//
//  Created by 高建 on 15/4/13.
//  Copyright (c) 2015年 xubin. All rights reserved.
//

#import "HotSiteDetailViewController.h"

@interface HotSiteDetailViewController ()

@end

@implementation HotSiteDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.navigationController setNavigationBarHidden:YES];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.myHotTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //取消了横线
    self.myHotTableView.separatorStyle = NO;
    [self.view addSubview:self.myHotTableView];
    self.myHotTableView.delegate = self;
    self.myHotTableView.dataSource = self;
    [self.myHotTableView release];
    self.mainHotArray = [NSMutableArray array];
    //创建model对象将其放入数组中
    //进行判断 有的可以显示数据没有不会站位
    if (![self.myHotSiteDetail.descriptions isEqualToString:@""]) {
        //字符串拼接
        NSString *description = [NSString stringWithFormat:@"📒  概述:%@", self.myHotSiteDetail.descriptions];
        [self.mainHotArray addObject:description];
    }if (![self.myHotSiteDetail.address isEqualToString:@""]) {
        NSString *address = [NSString stringWithFormat:@"📬  地址:%@",self.myHotSiteDetail.address];
        [self.mainHotArray addObject:address];
    }if (![self.myHotSiteDetail.arrival_type isEqualToString:@""]) {
        NSString *arrival_type = [NSString stringWithFormat:@"🚠  到达方式:%@",self.myHotSiteDetail.arrival_type];
        [self.mainHotArray addObject:arrival_type];
        
    }if (![self.myHotSiteDetail.opening_time isEqualToString:@""]) {
        NSString *opening_time = [NSString stringWithFormat:@"⌚️  开放时间:%@",self.myHotSiteDetail.opening_time];
        [self.mainHotArray addObject:opening_time];
        
    }if (![self.myHotSiteDetail.fee isEqualToString:@""]) {
        NSString *fee = [NSString stringWithFormat:@"💰  人均消费:%@", self.myHotSiteDetail.fee];
        [self.mainHotArray addObject:fee];
        
    }if (![self.myHotSiteDetail.tel isEqualToString:@""]) {
        NSString *tel = [NSString stringWithFormat:@"📱  联系方式:%@",self.myHotSiteDetail.tel];
        [self.mainHotArray addObject:tel];
        
    }if (![self.myHotSiteDetail.website isEqualToString:@""]) {
        NSString *website = [NSString stringWithFormat:@"🎬  官方网址:%@",self.myHotSiteDetail.website];
        [self.mainHotArray addObject:website];
        
    }

    
    //创建一个View
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 2)];
    headView.backgroundColor = [UIColor blackColor];
    [self.myHotTableView addSubview:headView];
    self.myHotTableView.tableHeaderView = headView;
    
    UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, headView.frame.size.height / 8 * 5)];
    myImageView.backgroundColor = [UIColor greenColor];
    [headView addSubview:myImageView];
    [myImageView sd_setImageWithURL:[NSURL URLWithString:self.myHotSiteDetail.cover_route_map_cover]];
    myImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [myImageView addGestureRecognizer:tap];
    [tap release];
    
    UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [aButton setBackgroundImage:[UIImage imageNamed:@"iconfont-fanhui-2.png"] forState:UIControlStateNormal];
    [aButton addTarget:self action:@selector(popAction:) forControlEvents:UIControlEventTouchUpInside];
    aButton.frame = CGRectMake(15, 25, 30, 30);
    [myImageView addSubview:aButton];
    
    
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, headView.frame.size.height / 8 * 5, self.view.frame.size.width, headView.frame.size.height / 8)];
    nameLabel.backgroundColor = [UIColor whiteColor];
    [headView addSubview:nameLabel];
    nameLabel.text = self.myHotSiteDetail.name;
    nameLabel.textAlignment = NSTextAlignmentCenter;
    nameLabel.font = [UIFont systemFontOfSize:30.0];
    
//    UILabel *starLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, headView.frame.size.height / 2 + 80, self.view.frame.size.width, 40)];
//    starLabel.backgroundColor = [UIColor yellowColor];
//    [headView addSubview:starLabel];
    
    UILabel *recommended_reasonLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, headView.frame.size.height / 4 * 3, self.view.frame.size.width, headView.frame.size.height / 8)];
    recommended_reasonLabel.backgroundColor = [UIColor whiteColor];
    [headView addSubview:recommended_reasonLabel];
    recommended_reasonLabel.text = self.myHotSiteDetail.recommended_reason;
    recommended_reasonLabel.numberOfLines = 0;
    recommended_reasonLabel.textAlignment = NSTextAlignmentCenter;
    
    
    //基本信息
    UILabel *basicLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, headView.frame.size.height / 8 * 7, self.view.frame.size.width, headView.frame.size.height / 8)];
    basicLabel.backgroundColor = [UIColor whiteColor];
    basicLabel.text = @"----<基本信息>----";
    basicLabel.textAlignment = NSTextAlignmentCenter;
    basicLabel.font = [UIFont systemFontOfSize:20.0];
    [headView addSubview:basicLabel];
//    self.mainHotArray = [NSMutableArray array];
    
}
- (void) popAction:(UIButton *)aButton
{
    [self.navigationController popViewControllerAnimated:YES];
    [self.navigationController setNavigationBarHidden:NO];
}
- (void)tapAction:(UITapGestureRecognizer *)tapAction
{
    photoSecondViewController *SecondPhoto = [[photoSecondViewController alloc]init];
    SecondPhoto.SecondId =self.myHotSiteDetail.photoId;
    [self.navigationController pushViewController:SecondPhoto animated:YES];
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return [self heightForCell:[self.mainHotArray objectAtIndex:indexPath.row]] + 5;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mainHotArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";
    HotSiteTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[HotSiteTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
//        NSLog(@"+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+%@",self.mainHotArray);
        
        //自适应label高度
        CGRect fram = cell.mainLabel.frame;
        fram.size.height = [ [HotSiteTableViewCell class] heightForCell: [self.mainHotArray objectAtIndex:indexPath.row] ];
        cell.mainLabel.frame = fram;
        cell.mainLabel.text = [self.mainHotArray objectAtIndex:indexPath.row];
        
        
        
        
    }
    return cell;
}



- (CGFloat)heightForCell:(NSString *)content
{
    //方法体内写 根据内容计算高度的逻辑
    //参数1.设置内容显示大小
    //参数2.设置内容计算类型
    //参数3.设置内容字体大小
    //参数4.苹果备用参数,设置为nil
    
    //设置计算内容的宽度一定要与显示内容的label宽度一样,高度可以设置大一些
    CGSize size = CGSizeMake(WidthZ - 20 , 2000);
    //将字体属性放入到字典中
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17.0] forKey:NSFontAttributeName];
    //根据文字内容计算出内容大小
    
    
    CGRect frame = [content boundingRectWithSize:size options: NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return frame.size.height;
    
    
}









- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}








/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
